//
//  ZLCourseLearningDetailHeaderView.m
//  ZLExamination
//
//  Created by Zheng on 2017/9/8.
//  Copyright © 2017年 Zheng. All rights reserved.
//

#import "ZLCourseLearningDetailHeaderView.h"

@implementation ZLCourseLearningDetailHeaderView

#pragma mark - 点击事件
- (void)clickAction:(UIControl *)sender {
    if (_clickCallBack) {
        _clickCallBack(_beginExamLbl);
    }
}

#pragma mark - 初始化方法
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self addSubview:self.timeTitleLbl];
        [self addSubview:self.timeValueLbl];
        [self addSubview:self.lineView];
        [self addSubview:self.progressTitleLbl];
        [self addSubview:self.progressValueLbl];
        [self layoutTopSubviews];
        
        [self addSubview:self.beginExamView];
        [self.beginExamView addSubview:self.iconView];
        [self.beginExamView addSubview:self.beginExamLbl];
        [self.beginExamView addSubview:self.whiteImgv];
        [self layoutMiddleSubviews];
        
        [self addSubview:self.allTitleLbl];
        [self addSubview:self.allValueLbl];
        [self addSubview:self.promptLbl];
        [self layoutBottomSubviews];
        
    }
    return self;
}

#pragma mark - 约束
- (void)layoutBottomSubviews {
    
    [_allTitleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(-7);
        make.left.mas_equalTo(15);
    }];
    
    [_allValueLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_allTitleLbl.mas_right).offset(7);
        make.bottom.equalTo(_allTitleLbl).offset(-2);
    }];
    
    [_promptLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-15);
        make.bottom.equalTo(_allTitleLbl).offset(-2);
    }];
}

- (void)layoutMiddleSubviews {
    
    [_beginExamView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(kSCREEN_WIDTH-20);
        make.centerX.equalTo(self);
        make.height.mas_equalTo(60);
        make.top.mas_equalTo(85);
    }];
    
    [_iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(7);
        make.width.height.mas_equalTo(37);
        make.centerY.equalTo(_beginExamView);
    }];
    
    [_beginExamLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_iconView.mas_right).offset(15);
        make.centerY.equalTo(_beginExamView);
    }];
    
    [_whiteImgv mas_makeConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(10);
        make.height.mas_equalTo(15);
        make.right.mas_equalTo(-10);
        make.centerY.equalTo(_beginExamView);
    }];
}


- (void)layoutTopSubviews {
    
    [_timeTitleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self).multipliedBy(0.4);
        make.top.mas_equalTo(20);
    }];
    
    [_timeValueLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_timeTitleLbl);
        make.top.equalTo(_timeTitleLbl.mas_bottom).offset(5);
    }];
    
    [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self);
        make.top.equalTo(_timeTitleLbl);
        make.bottom.equalTo(_progressValueLbl);
        make.width.mas_equalTo(0.5);
    }];
    
    [_progressTitleLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self).multipliedBy(1.5);
        make.top.mas_equalTo(20);
    }];
    
    [_progressValueLbl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(_progressTitleLbl);
        make.top.equalTo(_progressTitleLbl.mas_bottom).offset(5);
    }];
}

#pragma mark - 子视图
- (UILabel *)promptLbl {
    if (!_promptLbl) {
        _promptLbl = [[UILabel alloc] init];
        _promptLbl.font = kMyFont(10);
        _promptLbl.textColor = [UIColor lightGrayColor];
        _promptLbl.text = @"完成一个章节进度方可解锁下一章";
    }
    return _promptLbl;
}

- (UILabel *)allValueLbl {
    if (!_allValueLbl) {
        _allValueLbl = [[UILabel alloc] init];
        _allValueLbl.font = kMyFont(10);
        _allValueLbl.textColor = [UIColor lightGrayColor];
        _allValueLbl.hidden = YES;
    }
    return _allValueLbl;
}

- (UILabel *)allTitleLbl {
    if (!_allTitleLbl) {
        _allTitleLbl = [[UILabel alloc] init];
        _allTitleLbl.font = kMyFont(14);
        _allTitleLbl.text = @"全部章节";
    }
    return _allTitleLbl;
}

- (UILabel *)beginExamLbl {
    if (!_beginExamLbl) {
        _beginExamLbl = [[UILabel alloc] init];
        _beginExamLbl.textColor = [UIColor whiteColor];
        _beginExamLbl.font = kMyFont(16);
    }
    return _beginExamLbl;
}

- (UIImageView *)whiteImgv {
    if (!_whiteImgv) {
        _whiteImgv = [[UIImageView alloc] init];
        _whiteImgv.image = kIMAGE(@"learn_white");
    }
    return _whiteImgv;
}

- (UIImageView *)iconView {
    if (!_iconView) {
        _iconView = [[UIImageView alloc] init];
        _iconView.image = kIMAGE(@"learn_e_icon");
    }
    return _iconView;
}


- (UIControl *)beginExamView {
    if (!_beginExamView) {
        _beginExamView = [[UIControl alloc] init];
        _beginExamView.backgroundColor = kMY_BLUE_COLOR;
        _beginExamView.layer.cornerRadius = 3;
        [_beginExamView addTarget:self action:@selector(clickAction:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _beginExamView;
}


- (UIView *)lineView {
    if (!_lineView) {
        _lineView = [[UIView alloc] init];
        _lineView.backgroundColor = kRGB_COLOR(228, 228, 228, 1);
    }
    return _lineView;
}

- (UILabel *)progressValueLbl {
    if (!_progressValueLbl) {
        _progressValueLbl = [[UILabel alloc] init];
        _progressValueLbl.font = kMyFont(21);
        _progressValueLbl.textColor = kRGB_COLOR(51, 51, 51, 1);
        _progressValueLbl.textAlignment = NSTextAlignmentCenter;
    }
    return _progressValueLbl;
}


- (UILabel *)progressTitleLbl {
    if (!_progressTitleLbl) {
        _progressTitleLbl = [[UILabel alloc] init];
        _progressTitleLbl.font = kMyFont(16);
        _progressTitleLbl.textColor = kRGB_COLOR(51, 51, 51, 1);
        _progressTitleLbl.textAlignment = NSTextAlignmentCenter;
        _progressTitleLbl.text = @"学习进度";
    }
    return _progressTitleLbl;
}

- (UILabel *)timeValueLbl {
    if (!_timeValueLbl) {
        _timeValueLbl = [[UILabel alloc] init];
        _timeValueLbl.font = kMyFont(21);
        _timeValueLbl.textColor = kRGB_COLOR(51, 51, 51, 1);
        _timeValueLbl.textAlignment = NSTextAlignmentCenter;
    }
    return _timeValueLbl;
}

- (UILabel *)timeTitleLbl {
    if (!_timeTitleLbl) {
        _timeTitleLbl = [[UILabel alloc] init];
        _timeTitleLbl.font = kMyFont(16);
        _timeTitleLbl.textColor = kRGB_COLOR(51, 51, 51, 1);
        _timeTitleLbl.textAlignment = NSTextAlignmentCenter;
        _timeTitleLbl.text = @"学习时长";
    }
    return _timeTitleLbl;
}














@end
